package game

import (
	"061/Sgame/db"
	"061/Sgame/net"
	"061/Sgame/server/game/controller"
	"061/Sgame/server/game/gameConfig"
	"061/Sgame/server/game/gameConfig/general"
	"061/Sgame/server/game/logic"
	"061/Sgame/server/game/model/data"
	"061/Sgame/server/login/model"
	"061/Sgame/server/models"
	"fmt"
)

var Router = net.NewRouter()

func Init() {
	//初始化数据库
	db.TestDB()
	//迁移表
	MigrateTable()
	//加载基础配置
	gameConfig.Base.Load()
	//加载地图的资源配置
	gameConfig.MapBuildConf.Load()
	//加载地图单元格配置
	gameConfig.MapRes.Load()
	//加载武将配置信息
	general.GeneralConf.Load()
	//加载城池设施配置
	gameConfig.FacilityConf.Load()
	//加载技能
	gameConfig.Skill.Load()

	logic.BeforeInit()

	//加载所有的建筑信息
	logic.RoleBuildService.Load()
	//加载所有的城池信息
	logic.RoleCityService.Load()
	//加载联盟的所有信息
	logic.CoalitionService.Load() //先与角色属性加载
	//加载所有的角色属性
	logic.RoleAttrService.Load()

	InitRouter()
}

// InitRouter 初始化路由
func InitRouter() {
	controller.DefaultRoleController.Router(Router)
	controller.DefaultNationMapController.Router(Router)
	//武将
	controller.GeneralHandler.Router(Router)
	//军队
	controller.DefaultArmyController.Router(Router)
	//战报
	controller.WarController.Router(Router)
	//技能
	controller.SkillController.Router(Router)
	//征收
	controller.InteriorController.Router(Router)
	//联盟
	controller.UnionController.Router(Router)
	//设施
	controller.CityController.Router(Router)
}
func MigrateTable() {
	err := db.GormDB.AutoMigrate(
		data.Role{}, data.RoleRes{}, model.LoginHistory{}, model.LoginLast{}, models.User{},
		data.RoleAttribute{}, data.MapRoleCity{}, data.MapRoleBuild{}, data.General{}, data.Army{},
		data.WarReport{}, data.Skill{}, data.CityFacility{}, data.CoalitionApply{}, data.Coalition{},
		data.CoalitionLog{},
	)
	if err != nil {
		fmt.Println("迁移表失败。。。", err)
		return
	}
}
